<?php

namespace Admin\Controller;

header('content-type:text/html;charset=utf8');
class SxlController extends AdminController {
    public function index(){
    	 	$nickname       =   I('nickname');
            $map['status']  =   array('egt',0);
            if(is_numeric($nickname)){
                $map['id|name'] =   array(intval($nickname),array('like','%'.$nickname.'%'),'_multi'=>true);
            }else{
                $map['name']    =   array('like', '%'.(string)$nickname.'%');
            }
            $res=M('goods')->getField('id,name');
            $list   = $this->lists('classify',$map,'id asc');
            // dump($res);
            int_to_string($list);
            $this->assign('_list', $list);
            $this->assign('res', $res);
            $this->meta_title = '属性类别';
            $this->display();
    }
    public function add($id='',$n=''){
    	//dump(array($id,$n));
    	if(IS_POST){
    			$qus=I("post.");
              	$qus['gid']=$id;
              	
                $Link = D("classify");
                $res = $Link->create($qus); // dump($qus);die;
                if($res){
                    if($Link->add($qus)){
                        $this->success('添加成功');
                    }else{
                        $this->error('添加失败');
                    }
                }else{
                    $this->error(D("classify")->getError());
                }
            }else{
            	    $this->assign('id',$id);
                    $this->assign('name',$n);
    			    $this->display();
            }
    }

    public function del($id=''){
    		$res=M('classify')->where(array('id'=>$id))->delete();
    		if($res){
    			$this->success('删除成功');
    		}else{
    			$this->error('删除失败');
    		}
    }


}
